---------------------------------------------------------------------------------------------------- -- Mob Jump ---------------------------------------------------------------------------------------------------- -- Разработчик: Jim ---------------------------------------------------------------------------------------------------- local STATE_START_LOOK = 1 local STATE_WAIT_LOOK_END = 2 local STATE_JUMP = 3 class "mob_jump" ---------------------------------------------------------------------------------------------------- -- CONSTRUCTION SCHEME ---------------------------------------------------------------------------------------------------- function mob_jump:__init(obj, storage) self.object = obj self.st = storage end ---------------------------------------------------------------------------------------------------- -- RESET SCHEME ---------------------------------------------------------------------------------------------------- function mob_jump:reset_scheme() printf("Jump: reset_scheme: %s", self.object:name()) xr_logic.mob_capture(self.object, true) -- reset signals self.st.signals = {} -- initialize jump point self.jump_path = self.st.jump_path_name and patrol(self.st.jump_path_name) if not self.jump_path then abort("object '%s': unable to find jump_path '%s' on the map",self.object:name(), self.st.jump_path_name) end self.point = vector().add(self.jump_path:point(0), self.st.offset) self.state_current = STATE_START_LOOK end ---------------------------------------------------------------------------------------------------- -- UPDATE ---------------------------------------------------------------------------------------------------- function mob_jump:update(delta) --[[ if xr_logic.try_switch_to_another_section(self.object, self.st, db.actor) then return end ]] if (self.state_current == STATE_START_LOOK) then if not self.object:action() then action( self.object, look(look.point, self.point), cond(cond.look_end) ) self.state_current = STATE_WAIT_LOOK_END end elseif (self.state_current == STATE_WAIT_LOOK_END) then if not self.object:action() then self.state_current = STATE_JUMP end end if self.state_current == STATE_JUMP then self.object:jump(self.point, self.st.ph_jump_factor) self.st.signals["jumped"] = true xr_logic.mob_release(self.object) end end ---------------------------------------------------------------------------------------------------- -- ADD_TO_BINDER ---------------------------------------------------------------------------------------------------- function add_to_binder(npc, ini, scheme, section, storage) --printf("DEBUG: add_to_binder: npc:name()='%s', scheme='%s', section='%s'", npc:name(), scheme, section) local new_action = mob_jump(npc, storage) -- Зарегистрировать все actions, в которых должен быть вызван метод reset_scheme при изменении настроек схемы: xr_logic.subscribe_action_for_events(npc, storage, new_action) end ---------------------------------------------------------------------------------------------------- -- set_scheme ---------------------------------------------------------------------------------------------------- function set_scheme(npc, ini, scheme, section, gulag_name) local storage = xr_logic.assign_storage_and_bind(npc, ini, scheme, section) storage.logic = xr_logic.cfg_get_switch_conditions(ini, section, npc) storage.jump_path_name = utils_data.prefix_r_string(ini,section,"path_jump",gulag_name) if not level.patrol_path_exists(storage.jump_path_name) then storage.jump_path_name = ini:r_string_ex(section,"path_jump") if not (level.patrol_path_exists(storage.jump_path_name)) then printe("!ERROR: mob_jump: patrol path %s does not exist",storage.jump_path_name) end end storage.ph_jump_factor = ini:r_string_ex(section,"ph_jump_factor") or 1.8 local offset_str = ini:r_string_ex(section,"offset") if (offset_str) then local elems = parse_names(offset_str) storage.offset = vector():set(tonumber(elems[1]) or 0, tonumber(elems[2]) or 0, tonumber(elems[3]) or 0) else storage.offset = VEC_ZERO end if not ini:line_exist( section, "on_signal" ) then abort("Bad jump scheme usage! `on_signal` line must be specified") end end